package com.ibuonline.b2b.entity;

import java.io.Serializable;

import com.ibuonline.b2b.common.CategoryUtil;
import com.ibuonline.b2b.common.SysCache;

public class ProdCategory implements Serializable{

	private static final long serialVersionUID = -3081283373178851705L;

	//fields
	private java.lang.Integer id;
	private java.lang.String name;
	private java.lang.String displayName;
	private java.lang.String disNameEncode;
	private java.lang.Boolean display;
	private java.lang.String path;
	private java.lang.String initial;
	private java.lang.String url;
	private java.lang.Boolean leafNode;

	//default constructor
	public ProdCategory() {
	}

	//getter
	public java.lang.Integer getId() {
		return id;
	}
	public java.lang.String getName() {
		return name;
	}
	public java.lang.String getDisplayName() {
		return displayName;
	}
	public java.lang.Boolean isDisplay() {
		return display;
	}
	public java.lang.String getPath() {
		return path;
	}
	public java.lang.String getInitial() {
		return initial;
	}
	public java.lang.String getUrl() {
		return url;
	}
	public java.lang.Boolean isLeafNode() {
		return leafNode;
	}

	//setter
	public void setId(java.lang.Integer id) {
		this.id = id;
	}
	public void setName(java.lang.String name) {
		this.name = name;
	}
	public void setDisplayName(java.lang.String displayName) {
		this.displayName = displayName;
	}
	public void setDisplay(java.lang.Boolean display) {
		this.display = display;
	}
	public void setPath(java.lang.String path) {
		this.path = path;
	}
	public void setInitial(java.lang.String initial) {
		this.initial = initial;
	}
	public void setUrl(java.lang.String url) {
		this.url = url;
	}
	public void setLeafNode(java.lang.Boolean leafNode) {
		this.leafNode = leafNode;
	}

	//equals method
	public boolean equals(Object other) {
		if (this == other)
			return true;
		if (!(other instanceof ProdCategory))
			return false;

		final ProdCategory prodCategory = (ProdCategory)other;
		if (!this.id.equals(prodCategory.getId()))
			return false;

		return true;
	}

	//hashCode method
	public int hashCode() {
		StringBuffer keys = new StringBuffer();
		keys.append(id).append(",");
		if (keys.length() > 0)
			keys.deleteCharAt(keys.length() - 1);
		return keys.toString().hashCode();
	}

	//toString method
	public String toString() {
		return new StringBuilder("ProdCategory[")
			.append("id=").append(id).append(", ")
			.append("name=").append(name).append(", ")
			.append("displayName=").append(displayName).append(", ")
			.append("display=").append(display).append(", ")
			.append("path=").append(path).append(", ")
			.append("initial=").append(initial).append(", ")
			.append("url=").append(url).append(", ")
			.append("leafNode=").append(leafNode).append("]").toString();
	}

	///############
	private int displayOrder;
	private int parentId;
	private int level;
	private int count;
	
	
	public int getLevel() {
		ProdCategory cat = SysCache.getCategory(id);
		String path = cat.getPath();
		level = path.split("-").length;
		return level;
	}
	
	public String getTopCategoryName(){
		if (this.id != null) {
			return CategoryUtil.getCategoryPath(this.id);
		}
		return "";
	}

	public void setLevel(int level) {
		this.level = level;
	}
	public int getDisplayOrder() {
		return displayOrder;
	}

	public void setDisplayOrder(int displayOrder) {
		this.displayOrder = displayOrder;
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}
	
	public boolean getLeafNode() {
		return leafNode;
	}
	
	public boolean getDisplay() {
		return display;
	}

	public java.lang.String getDisNameEncode() {
		return disNameEncode;
	}

	public void setDisNameEncode(java.lang.String disNameEncode) {
		this.disNameEncode = disNameEncode;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
	
}
